package com.example.mybatis;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Date 2022/1/19
 * @Created by Jonathan
 */
public class ImportRegisterDemo implements ImportBeanDefinitionRegistrar {
	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		// todo
		// 1. 创建BD
		// 包装成一个类
		//BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(接口的实现类|代理类);
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FactoryBeanDemo.class);
		GenericBeanDefinition beanDefinition = (GenericBeanDefinition) builder.getBeanDefinition();
		// 2. BD进行注册
		registry.registerBeanDefinition("userDAO", beanDefinition);
	}
}
